﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http;
using System.Net.Http;
using System.Web.Mvc;
using TimeTracker.Data.Contracts;
using TimeTracker.Model;
using System.Net;

namespace TimeTracker.WebUI.Controllers
{
    public class ActivitiesController : ApiBaseController
    {
        public ActivitiesController(ITimeTrackerUow uow)
        {
            Uow = uow;
        }

        // GET /api/activities
        public IEnumerable<Activity> Get()
        {
            return Uow.Activities.GetAll().OrderBy(p => p.Name);
        }

        // GET /api/activities/5
        public Activity Get(int id)
        {
            var activity = Uow.Activities.GetById(id);
            if(activity != null)
                return activity;

            throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotFound));
        }

        public HttpResponseMessage Put(Activity activity)
        {
            Uow.Activities.Update(activity);
            Uow.Commit();
            return new HttpResponseMessage(HttpStatusCode.NoContent);
        }

    }
}
